﻿using JTActiveSafety.Protocol.Extensions;
using System;
using System.Text;

namespace JTActiveSafety.Gateway.Models
{
    public class AttachFileName
    {
        public AttachFileName(string terminalPhoneNo,string filename)
        {  
            if (string.IsNullOrWhiteSpace(filename) || string.IsNullOrWhiteSpace(terminalPhoneNo)) {
                return;
            }
            FileName = filename;
            TerminalPhoneNo = terminalPhoneNo;
            try
            {
                var x = filename.Split("_", StringSplitOptions.RemoveEmptyEntries);
                if (x.Length == 5)
                {
                    AlarmCode = x[2];
                    SN = x[3];
                    var ss = x[4];
                    if (ss.Length > 32)
                    {
                        //TerminalPhoneNo = Encoding.Default.GetString(ss.Substring(0, 14).ToHexBytes()).Trim(default(char));// ss.Substring(0,14);
                        Date = ss.Substring(14, 6);
                        Time = ss.Substring(20, 6);
                    }
                }
                IsValid = true;
            }
            catch (Exception)
            {
            }
        }
        public string FileName { get; private set; }
        public string TerminalPhoneNo { get; private set; }
        public string Date { get; private set; }
        public string Time { get; private set; }

        public string SN { get; private set; }

        public string AlarmCode { get; private set; }

        public bool IsValid { get; private set; } = false;
    }

}
